package com.spring.hotel.controller;

import com.spring.hotel.common.JsonResponse;
import com.spring.hotel.entity.Member;
import com.spring.hotel.entity.PageDTO;
import com.spring.hotel.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/hotel/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    //添加
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public JsonResponse insert(@RequestBody Member member) {
        memberService.save(member);
        return JsonResponse.success(null);
    }

    //修改
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public JsonResponse updateUser(@RequestBody Member member) throws Exception {
        memberService.updateById(member);
        return JsonResponse.success(null);
    }

    //删除
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
    public JsonResponse delete(@PathVariable String id) {
        memberService.removeById(id);
        return JsonResponse.success(null);
    }

    //分页查询
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResponse list(Member member, PageDTO pageDTO) {
        return memberService.pageList(member,pageDTO);
    }
}
